
<div class="pageContent">
      <form id="myform" action="{:U('Order/orderdone')}" method="post" onsubmit="return validateCallback(this,dialogAjaxDone);">
        <input type='hidden' name='data[id]' value='{$info.id}' />
        <input type='hidden' name='key' value="{$inf.key}" />
		<div class="pageFormContent nowrap" layoutH="97">
            <dl>
                <dt>
                    用户：
                </dt>
                <dd>
                	<input id="useruid" name="user.id" value="" type="hidden"/>
					<input class="required autoinput" name="user.username" value="{$info.username}{$inf['username']}" type="text" postField="keywords" suggestFields="id,username" suggestUrl="{:U('User/suggest',array('tn'=>'user','fn'=>'id,username','field'=>'id,username','where'=>myencode(array('status'=>1),1)))}" lookupGroup="user"/>                 
                </dd>
            </dl>
            <dl>
                <dt>
                   选择 商品：
                </dt>
                <dd>
                	<input   id='proid' name="product.id" value="{$inf['userid']}{$info.userid}" type="hidden"/>
					<input style='width:450px;' id='proname' name="product.name" value="" type="text" postField="keywords" suggestFields="id,name,price" suggestUrl="{:U('Content/suggest',array('tn'=>'product','fn'=>'id,name','field'=>'id,name,price,image,code,mname','where'=>myencode(array('status'=>1),1)))}" lookupGroup="product"/>                 
                	<input readonly='readonly' id='proprice' name="product.price" value="" type="hidden"/>
					<input readonly='readonly' id='propimag' name="product.image" value="" type="hidden"/>
					<input readonly='readonly' id='procode' name="product.code" value="" type="hidden"/>
					<input readonly='readonly' id='promname' name="product.mname" value="" type="hidden"/>
					<input type='button' id='addpro' value='添加' />
				</dd>
            </dl>
			   <dl >
                <dt>
                    商品：
                </dt>
                <dd style='width:800px;'>
                 <div id='txtproduct'></div>
                </dd>
            </dl>
            <dl>
                <dt>
                    &nbsp;
                </dt>
                <input id="getaddr" type="button" value='获取收货地址' />
            </dl>
            <dl>
                <dt>
                    收货地址：
                </dt>
                <dd>
                    <div id='txtuseraddr'></div>
                </dd>
            </dl>
       
        </div>
        <div class="formBar">
            <ul>
                <li>
                    <div class="buttonActive">
                        <div class="buttonContent">
                            <button type="submit">
                                保存
                            </button>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="button">
                        <div class="buttonContent">
                            <button type="button" class="close">
                                取消
                            </button>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
    </form>
</div>
<script>
	$(function(){
		//添加商品
		$("#addpro").click(function(){
			var id = $("#proid").val();
			var name = $("#proname").val();
			var price = $("#proprice").val();
			var img = $("#propimag").val();
			var code = $("#procode").val();
			var mname = $("#promname").val();
			//alert(id);alert(name);alert(price);
			if(!id || !name || !price){
				alert('选择商品错误，请从弹出框中进行选择！');
				return false;
			}
			$("#proname").val("");
			var htmlval = $("#txtproduct").html();
			htmlval += "<div id='divprod"+id+"'>";
			
			htmlval += "<input style='width:50px;' name='proids[]' id='id"+id+"' type='hidden' readonly='readonly' value='"+id+"' />";
			htmlval += "<input style='width:50px;' name='proprice[]' id='price"+id+"' type='hidden' readonly='readonly' value='"+price+"' />";
			htmlval += "<input style='width:50px;' name='proimg[]' id='img"+id+"' type='hidden' readonly='readonly' value='"+img+"' />";
			htmlval += "<input style='width:50px;' name='proname[]' id='name"+id+"' type='hidden' readonly='readonly' value='"+name+"' />";
			htmlval += "<input style='width:50px;' name='procode[]' id='code"+id+"' type='hidden' readonly='readonly' value='"+code+"' />";
			htmlval += "<input style='width:50px;' name='promname[]' id='mname"+id+"' type='hidden' readonly='readonly' value='"+mname+"' />";
			htmlval += "<b>ID</b>："+id+"&nbsp;&nbsp;&nbsp;&nbsp;<b>名称</b>："+name+"&nbsp;&nbsp;&nbsp;&nbsp;<b>价格</b>：<font color='red'>"+price+"</font>&nbsp;&nbsp;&nbsp;&nbsp;";	
			htmlval += "数量:<input style='width:50px;' name='pronum[]' id='num"+id+"' type='text'  value='1' />&nbsp;&nbsp;";
			htmlval += "<input type='button' onclick='delpro("+id+")' value='删除' butid="+id+" />";
			htmlval += "<br />";
			htmlval += "</div>";
			
			$('#txtproduct').html(htmlval);
					
		});
		
		//删除一个商品
		$(".delpro").click(function(){alert(444);
//			var id = $(this).attr('attid');alert(id);
//			var divobj = creatElement("divprod"+id);
//
//			divobj.parentNode.removeChild(divobj);
  
		});
		
	
		
		//获取收货地址
		$("#getaddr").click(function(){
			var uid = $("#useruid").val();
			if(!uid){
				alert('请选择用户!');
				return false;
			}
			var url = "{:U('User/ajaxaddr')}";
			  $.ajax({
                type: "get",
                url: url+"&uid=" + uid,
                success: function(msg){
					if(!msg){
						alert('该用户没有填写任何收货地址,请与该用户联系！');
						return false;
					}
				
					var htmlval = '' ;
                    for(var i=0;i<msg.length;i++){					
						htmlval += "<input name='useraddr' value='"+msg[i]['id']+"' type='radio' />&nbsp;&nbsp;";					
						htmlval += msg[i]['name']+"&nbsp;&nbsp;"+msg[i]['province']+"&nbsp;&nbsp;"+msg[i]['city']+"&nbsp;&nbsp;"+msg[i]['area']+"&nbsp;&nbsp;"+msg[i]['address']+"&nbsp;&nbsp;";
						htmlval += msg[i]['tel']+"&nbsp;&nbsp;"+msg[i]['mobile']+"&nbsp;&nbsp;";
						htmlval += "<br />";
						
					}
					$('#txtuseraddr').html(htmlval);
                }
            });
		});
		
		$("#upimagebnt").uploadify({
                                                			'swf'         	:'__PUBLIC__/dwz146/uploadify/scripts/uploadify.swf',
                                                			'uploader'    	:'{:U("Refund/file_upload")}',
                                                			'auto'        	:true,
                                                			'formData'     	: {
                                                				'sess_id' : '<?php echo session_id();?>',
                                                			},
                                                			'fileTypeExts'  :'*.gif; *.jpg; *.png; *.jpeg',
                                                			'fileSizeLimit' :'300KB',//上传文件的大小限制，单位为B, KB, MB, 或 GB
                                                			'successTimeout':30,
                                                			//'buttonClass':'uploadButton',
                                                			'buttonText':'上传文件',
                                                			'multi'         :false,//单文件上传
                                            				'width'    : 60,
                                            				'height': 18,
                                                			'onUploadSuccess':function(file, data, response){
                                                				$("#upimage").val(data);
                												$("#main_img").attr("src",data);
                                                				//html=' <a target="_blank" href="'+data+'">查看</a>';
                                                				//$('#upimagedd').append(html);
                                                	        },
                                                	        'onUploadError':function(file, data, response){
                                                				alert(data+'上传失败，请重试');
                                                	        }
                                                		});
	});
	
	//删除商品
	function delpro(data){	
		var div=document.getElementById("divprod"+data);  
		div.parentNode.removeChild(div); 
		
	}
	
</script>